Skip to content

Tighten lambda captures, make small rendering and stats refactors, and improve safety, const-correctness, and debug-only checks across map, UI, OpenGL, and storage code. - #505

Merged
nschimme merged 3 commits into
MUME:masterfrom
nschimme:minor-fix
Apr 7, 2026

Conversation

@nschimme

@nschimme nschimme commented Apr 7, 2026

Copy link
Copy Markdown
Contributor

Summary by Sourcery

Tighten lambda captures, make small rendering and stats refactors, and improve safety, const-correctness, and debug-only checks across map, UI, OpenGL, and storage code.

Bug Fixes:

  • Fix RemoveAllDoorNames door-name removal to use a consistently scoped static default door name.
  • Correct GL compatibility probing loop to avoid redundant checks and ensure the first valid compat context is selected.
  • Stabilize DescriptionWidget background rendering by avoiding pointer aliasing and ensuring lambdas capture required state explicitly.

Enhancements:

  • Refactor World::printStats into a Stats helper struct with a dedicated print method and use colored numeric output consistently.
  • Adopt glm::lerp and glm compatibility headers for noise and weather interpolation instead of custom lerp helpers.
  • Constrain many lambdas across map, UI, OpenGL, and storage modules to explicit captures, improve const-correctness, and mark discardable functions and getters with NODISCARD/ALLOW_DISCARD where appropriate.
  • Use static or constexpr storage for various helper lambdas, lookup tables, and seed sets to reduce repeated initialization and clarify intent.

@sourcery-ai

sourcery-ai Bot commented Apr 7, 2026

Copy link
Copy Markdown

Reviewer's Guide

Refactors numerous lambdas and small helpers across the codebase to capture only what they use, improve const‑correctness and static storage, replace custom/hand‑rolled utilities with library functions (e.g., glm::lerp), and introduces a small stats struct in World::printStats for better encapsulation, while keeping behaviour essentially unchanged.

Class diagram for new Stats struct used in World::printStats

classDiagram
    class World {
        +void printStats(ProgressCounter pc, AnsiOstream os) const
    }

    class Stats {
        +size_t numMissingName
        +size_t numMissingDesc
        +size_t numMissingBoth
        +size_t numMissingArea
        +size_t numMissingServerId
        +size_t numWithNoConnections
        +size_t numWithNoExits
        +size_t numWithNoEntrances
        +size_t numExits
        +size_t numDoors
        +size_t numHidden
        +size_t numDoorNames
        +size_t numHiddenDoorNames
        +size_t numLoopExits
        +size_t numConnections
        +size_t numMultipleOut
        +size_t numMultipleIn
        +size_t adj1
        +size_t adj2
        +size_t non1
        +size_t non2
        +size_t loop1
        +size_t loop2
        +void print(AnsiOstream aos) const
    }

    World ..> Stats : uses in printStats
Loading

File-Level Changes

Change Details Files
Tighten lambda captures and lifetimes to avoid dangling references and unnecessary captures in map/world, UI, group, and storage code.
  • Make many for_each and higher‑order function lambdas capture this and only the specific variables they use instead of generic [&] captures to improve safety and clarity.
  • Adjust lambdas used in asynchronous or deferred contexts (e.g., RAII callbacks, Qt signal handlers) to capture this and any referenced objects explicitly, avoiding capturing temporaries or local references that might dangle.
  • Update MapFrontend::apply* and other helper lambdas to capture only the change list or config needed by the callback, decoupling them from surrounding state.
src/map/World.cpp
src/media/DescriptionWidget.cpp
src/map/Remapping.cpp
src/display/mapcanvas_gl.cpp
src/map/Map.cpp
src/display/Infomarks.cpp
src/map/World-BaseMap.cpp
src/mapfrontend/mapfrontend.cpp
src/mapstorage/XmlMapStorage.cpp
src/mapstorage/mapstorage.cpp
src/preferences/configdialog.cpp
src/display/Connections.cpp
src/global/emojis.cpp
src/group/groupwidget.cpp
src/group/mmapper2group.cpp
src/mainwindow/findroomsdlg.cpp
src/map/ParseTree.cpp
src/map/SpatialDb.cpp
src/opengl/legacy/SimpleMesh.h
Refactor World::printStats into a Stats helper struct with a dedicated print method and colored output helper, reducing local variable clutter.
  • Introduce a Stats struct encapsulating all counters previously defined as local size_t variables in World::printStats.
  • Move the formatted printing logic into Stats::print(AnsiOstream&) and invoke it at the end, instead of manually streaming each line in the function body.
  • Reuse a small helper (C) that wraps integer counters in ColoredValue with a constant green ANSI color, and call it from inside Stats::print and the overall stats output.
src/map/World.cpp
Improve numerical utilities and math usage in texture and weather code by reusing glm helpers, tightening types, and restructuring inner helper lambdas for reuse and performance clarity.
  • In Textures.cpp, add glm/gtx/compatibility.hpp and use glm::lerp instead of a custom lerp lambda for value noise interpolation.
  • Refactor createTileableValueNoiseImage: make hash and smootherstep helpers static, hoist get_wrapped_hash outside the pixel loop, use const/auto for temporaries, and use glm::lerp for bilinear interpolation.
  • Change createTileableValueNoiseImage parameter to const int and adjust other locals to be const or more narrowly scoped where appropriate.
  • In Weather.cpp, remove the custom templated lerp function and instead include glm/gtx/compatibility.hpp and call glm::lerp in GLWeather::applyTransition.
src/display/Textures.cpp
src/opengl/Weather.cpp
Clarify ownership and const‑discarding semantics in global color handling and game observer accessors.
  • In GlobalData, change setColor to take Color by const value and mark it ALLOW_DISCARD instead of relying on callers to std::ignore the result, so ignoring its return value is explicit and intentional.
  • Remove unnecessary std::ignore assignments around setColor calls when initializing default weather colors.
  • Annotate GameObserver getter methods with NODISCARD to flag accidental ignored uses of time, moon, season, weather, and fog state.
src/global/NamedColors.cpp
src/observer/gameobserver.h
Small logic and cleanup fixes in GL probing, OpenGL texture init, blur helpers, XML saving, and update dialog architecture detection.
  • In OpenGLProber::probeCompat, capture coreResult->version by value in the filtering lambda and remove a redundant inner validity check when choosing the highest compat version.
  • Make initGroup in MapCanvas::initTextures return SharedMMTexture and adjust maybeCreateArray to early‑return when the array already exists, clarifying control flow.
  • In DescriptionWidget::updateBackground, avoid storing a raw pointer to the base image; instead work with a reference and capture all needed values explicitly in the RAII painter lambda; also make stackBlur a static lambda taking radius as const int.
  • In Remapping, wrap debug‑only asserts and consistency checks in an if constexpr (IS_DEBUG_BUILD) block and adjust for_each lambdas to capture only what they use.
  • In UpdateDialog, make archPatterns and findPattern static, and capture arch by reference inside findPattern with a std::find_if over the static array.
  • Tighten types in various Qt signal/slot lambdas (e.g., sliders) to take const int parameters instead of int.
src/opengl/OpenGLProber.cpp
src/display/Textures.cpp
src/media/DescriptionWidget.cpp
src/map/Remapping.cpp
src/mainwindow/UpdateDialog.cpp
src/preferences/graphicspage.cpp

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - I've reviewed your changes and they look great!


Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@nschimme
nschimme merged commit 7f59bb9 into MUME:master Apr 7, 2026
1 check passed
@nschimme
nschimme deleted the minor-fix branch April 7, 2026 22:34
@codecov

codecov Bot commented Apr 7, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 10.10638% with 169 lines in your changes missing coverage. Please review.
✅ Project coverage is 25.10%. Comparing base (4a6ac7c) to head (9aff6fd).
⚠️ Report is 4 commits behind head on master.

Files with missing lines Patch % Lines
src/map/World.cpp 1.44% 68 Missing ⚠️
src/display/Textures.cpp 0.00% 32 Missing ⚠️
src/media/DescriptionWidget.cpp 0.00% 19 Missing ⚠️
src/opengl/OpenGLProber.cpp 0.00% 6 Missing ⚠️
src/display/Infomarks.cpp 0.00% 5 Missing ⚠️
src/display/mapcanvas_gl.cpp 0.00% 5 Missing ⚠️
src/map/Map.cpp 0.00% 5 Missing ⚠️
src/mainwindow/UpdateDialog.cpp 0.00% 4 Missing ⚠️
src/map/World-BaseMap.cpp 0.00% 3 Missing ⚠️
src/mapfrontend/mapfrontend.cpp 0.00% 3 Missing ⚠️
... and 13 more
Additional details and impacted files
@@           Coverage Diff           @@
##           master     #505   +/-   ##
=======================================
  Coverage   25.09%   25.10%           
=======================================
  Files         511      511           
  Lines       42313    42286   -27     
  Branches     4575     4574    -1     
=======================================
- Hits        10618    10615    -3     
+ Misses      31695    31671   -24     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@nschimme nschimme changed the title Minor fix Tighten lambda captures, make small rendering and stats refactors, and improve safety, const-correctness, and debug-only checks across map, UI, OpenGL, and storage code. Apr 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant